import request from '@/utils/request'


export const post = (url, data) => {
  data = data || {};


  return request({
      url: url,
      method: 'post',
      data
  })
}
//附件上传
export function upload  (data)  {
  let param = new FormData();
  for (var p in data) {
      param.append(p, data[p]);
  }
  return request({
      url: '/affix/upload',
      method: 'post',
      headers: {'Content-Type':'multipart/form-data'},
      data: param
  })
}

// 附件下载
export function download (fileId) {
  let data = {id: fileId};

  return request({
      url: '/affix/download',
      method: 'post',
      responseType: 'arraybuffer',
      data
  })
}

// 查询附件
export function queryAffixs (affixId)  {
  return request({
    url:'/affix/queryItems',
    method: 'post',
    data: {affixId: affixId}}
    );
}

// 删除附件
export function deleteAffix (fileId){
  return request(
    {
      url:'/affix/delete',
      method:'post',
      data:{id: fileId}
    }
  );
}

// 文件打包下载
export function downloadAll (affixId) {
  let data = {affixId: affixId};

  return request({
      url: '/affix/downloadAll',
      method: 'post',
      responseType: 'arraybuffer',
      data
  })
}

export function commonUpload (data) {
  let param = new FormData();
  for (var p in data) {
    param.append(p, data[p]);
  }
  return request({
      url: '/common/upload',
      method: 'post',
      headers: {'Content-Type':'multipart/form-data'},
      data: param
    });
}